﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Summary description for CustormerMethord
/// </summary>
public class CustormerMethord
{
	public CustormerMethord()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    SqlConnection sqlcon = Conection.getconnet();
    public void ConnectOpen() {
        if (sqlcon.State == ConnectionState.Closed) {
            sqlcon.Open();
        }
    }
    public  DataTable ProductDetails(int ID) {
        
        DataTable dt = new DataTable();
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("ProductDetails",sqlcon);
        sqlcom.Parameters.Add("@ProductID",ID);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();
        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
        sqlcon.Close();
    }
    //GioHang
    public DataTable Shopingview(int id) {
        DataTable dt = new DataTable();
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("ShopingView",sqlcon);
        sqlcom.Parameters.Add("@ProductID",id);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();
        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
    }
    //Dropdowlist Card
    public DataTable LoadCard() {
        DataTable dt = new DataTable();
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("LoadPay",sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();
        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
        sqlcon.Close();
    }
    public bool AddOrder(int Id, DateTime purchase, string status) {
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("AddOrder",sqlcon);
        sqlcom.Parameters.Add("@UserID",Id);
        sqlcom.Parameters.Add("@DateOfPurchase",purchase);
        sqlcom.Parameters.Add("@Status",status);
        sqlcom.CommandType = CommandType.StoredProcedure;
        try
        {
            sqlcom.ExecuteNonQuery();
            return true;
            sqlcon.Close();
        }
        catch (Exception ex) {
            return false;
            sqlcon.Close();        
        }
        return false;
    }
    public DataTable GetOrderID() {
        ConnectOpen();
        DataTable dt = new DataTable();
        SqlCommand sqlcom = new SqlCommand("GetOrderID", sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();
        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
        sqlcon.Close();
    }
    public bool AddOrderDetails(int Ordid,int ProId,float Prince,int Quantity,string Address,string comment) {
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("AddOderDetails",sqlcon);
        sqlcom.Parameters.Add("@OrderId",Ordid);
        sqlcom.Parameters.Add("@ProductID",ProId);
        sqlcom.Parameters.Add("@Price",Prince);
        sqlcom.Parameters.Add("@Quantity",Quantity);
        sqlcom.Parameters.Add("@Address",Address);
        sqlcom.Parameters.Add("@Comment",comment);
        sqlcom.CommandType = CommandType.StoredProcedure;
        try {
            sqlcom.ExecuteNonQuery();
            return true;
        }
        catch(Exception ex) {
            sqlcon.Close();
            return false;
        }
        return false;
    }
    //Home Load
    public DataTable Jewellry() {
        DataTable dt = new DataTable();
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("Jewellry_Home", sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;        
        sqlcom.ExecuteNonQuery();

        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];

            return dt;
            sqlcon.Close();
    }
    public DataTable Diamond() {
        DataTable dt = new DataTable();
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("Diamond_Home", sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();

        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
        sqlcon.Close();
    }
    public DataTable Stores() {
        DataTable dt = new DataTable();
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("Store_Home", sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();

        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
        sqlcon.Close();
    }
    public DataTable Gold() {
        DataTable dt = new DataTable();
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("Gold_Home", sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();

        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
        sqlcon.Close();
    }
    public DataTable ProductSimilar(string _Catname) {
        DataTable dt = new DataTable();
        ConnectOpen();
        SqlCommand sqlcom = new SqlCommand("ProductSimilar", sqlcon);
        sqlcom.Parameters.Add("@CatName", _Catname);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();

        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
        sqlcon.Close();
    }
}
